package com.cci.kangdao.dao;

import com.cci.kangdao.dao.model.FaultCodeT;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface FaultCodeTDao {

    //通过故障码获取故障码信息
    @Select("select Top 1 * from FaultCodeCummins_T where FaultCode = #{FaultCode} and Flag = 0")
    Map<String,Object> getFaultCodeCumminsTByFaultCode(@Param("FaultCode") String FaultCode);


    @Select("select ID as FaultCodeId,FaultCode,SPN,FMI,ISNULL(Description,'') as FaultCodeDescription from FaultCode_T where Flag = 0 and FaultCode like  concat('%',#{faultCode},'%') ")
    List<Map<String,Object>> getFaultCodeListByFaultCode(@Param("faultCode") String faultCode);

    //保证工单详情查看的数据是完整的   不加flag条件
    @Select("<script> select ID as FaultCodeId,FaultCode,SPN,FMI,ISNULL(Description,'') as FaultCodeDescription from FaultCode_T where ID in   <foreach collection='ids' item='item' open='(' separator=',' close=')'> #{item}  </foreach></script>")
    List<Map<String, Object>> getFaultCodeListByIds(@Param("ids") List<String> ids);

    @Select("select distinct ft.* from IsExistHandBookConfig_T  config left join CDSEngineInfo_T  enginfo  on enginfo.SMN= config.SMN\n" +
            "left join FaultCode_T  ft on ft.FaultCode=config.FaultCode\n" +
            "where config.SPN=#{SPN} and config.FMI=#{FMI} and enginfo.ESN=#{ESN} and ft.FMI=#{FMI} and  ft.SPN=#{SPN} and config.FaultCode is not null  and config.Flag=0 and enginfo.Flag=0 and ft.Flag=0")
    List<FaultCodeT> getFCCodeBySPNAndFMI(@Param("SPN") String spn, @Param("FMI") String fmi, @Param("ESN") String ESN);

}
